<?php
/**
 * Created by PhpStorm.
 * User: 陈艺赫
 * Date: 2017/12/8
 * Time: 0:42
 */

namespace Admin\Controller;


class CompanyController extends BaseController
{
    public function index()
    {
        $this->display();
    }

    public function dataGet()
    {
        if (IS_GET) {
            $db_com = M('company');
            $page = I('get.page');
            $limit = I('get.limit');
            if (empty(I('get.search'))) {
                $count = $db_com->where('status = 1')->count();
                $data_com = $db_com->where('status = 1')->page($page, $limit)->select();
            } else {
                $count = $db_com->where("status = 1 and txt like '%" . trim(I('get.search')) . "%'")->count();
                $data_com = $db_com->where("status = 1 and txt like '%" . trim(I('get.search')) . "%'")->page($page, $limit)->select();
            }
            $data['data'] = $data_com;
            $data['code'] = 0;
            $data['count'] = $count;
            $this->ajaxReturn($data);
        }

    }

    public function delTxt()
    {
        if (IS_POST) {
            $id = I('post.id');
            $db_name = M('company');
            $data_name = $db_name->where('id = ' . $id)->find();
            $data_name['status'] = 0;
            $result = $db_name->save($data_name);
            if ($result !== false) {
                $this->success('success');
            }
        }
        $this->error('error');
    }

    public function txtAdd()
    {
        if (IS_POST) {
            $data['txt'] = I('post.txt');
            $db_name = M('company');
            $result = $db_name->add($data);
            if ($result !== false) {
                $this->success('success');
            }
        }
        $this->error('error');
    }


}